package com.example.demo.ProxyMode;

/**
 * 游戏者(强制代理)
 */
public class GamePlayer2 implements IGamePlayer2{

    private String name;

    private IGamePlayer2 player2;

    public GamePlayer2(String name){
        this.name = name;
    }

    @Override
    public void login(String user, String password) {
        if(this.isProxy()){
            System.out.println("登录名为"+user+"的用户"+this.name+"登录成功！");
        }else{
            System.out.println("请使用指定的代理访问");;
        }
    }

    @Override
    public void killBoss() {
        if(this.isProxy()){
            System.out.println(this.name + "在打怪！");
        }else{
            System.out.println("请使用指定的代理访问");
        }
    }

    @Override
    public void upgrade() {
        if(this.isProxy()){
            System.out.println(this.name + " 又升了一级！");
        }else{
            System.out.println("请使用指定的代理访问");
        }
    }

    @Override
    public IGamePlayer2 getProxy() {
        this.player2 = new GamePlayerProxy2(this);
        return this.player2;
    }

    //校验是否是代理访问
    private boolean isProxy(){
        if(this.player2 == null){
            return false;
        }else{
            return true;
        }
    }
}
